package com.woniu.zsd.user.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniu.zsd.common.util.Result;
import com.woniu.zsd.user.controller.form.AddAddressForm;
import com.woniu.zsd.user.param.AddAddressParam;
import com.woniu.zsd.user.service.AddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjf
 * @since 2025年02月22日
 */
@RestController
@RequestMapping("/address")
@Api(tags = "地址管理")
public class AddressController {
    @Resource
    private AddressService addressService;
    //查询个人全部地址
    @GetMapping("/selectAddressByUserId")
    @ApiOperation(value = "查询个人全部地址")
    public Result selectAddressByUserId(Integer userId){
        return Result.success("查询成功",addressService.selectAddressByUserId(userId));
    }
    //新增个人地址
    @PostMapping("/addAddress")
    @ApiOperation(value = "新增个人地址")
    public Result addAddress(@RequestBody AddAddressForm form){
        addressService.addAddress(BeanUtil.toBean(form, AddAddressParam.class));
        return Result.success("新增成功");
    }

}

